#delimit;
capture log close;
set more off;
pause on;
clear all;
set scheme plottig;

cap cd "/Users/deandulay/Dropbox/Myanmar_JOP_EGI_replication";
cap cd "C:\Users\ejm5\Dropbox\Myanmar_JOP_EGI_replication";
use  "data\20220606_mbei_panel_working.dta", clear;

/***********************************************************************************************************************************************************/
/*Stack Data*/
keep Panel_ID year state_region township p_code q214 q10  Bcode weight_township PSW_FPC1 PSW_STRATA weight_township workshop capital literacy surface_area lag DAO_helpful DAO_pct town_type  count_ttype PSU t_q71_5_binary t_q143_4 DAO_indicators_final;

generate helpful=DAO_helpful;
generate info=DAO_pct;
generate DAO=1;
generate transparency =t_q71_5_binary;
generate favoritism = t_q143_4;
generate specialized=DAO_indicators_final;

save "data\mbei_panel_final_DAO.dta", replace;
use  "data\20220606_mbei_panel_working.dta", clear;

keep Panel_ID year state_region township p_code q214 q10  Bcode weight_township PSW_FPC1 PSW_STRATA weight_township workshop capital literacy surface_area lag GAD_helpful GAD_pct town_type  count_ttype PSU t_q112_7_binary t_q143_1 GAD_indicators_final;

/*Generate Measures*/
generate helpful=GAD_helpful;
generate info=GAD_pct;
generate DAO=0;
generate transparency =t_q112_7_binary;
generate favoritism = t_q143_1;
generate specialized=GAD_indicators_final;

save "data\mbei_panel_final_GAD.dta", replace;
append using "data\mbei_panel_final_DAO.dta";
/***********************************************************************************************************************************************************/

/***********************************************************************************************************************************************************/
/*Table F1 Direct Comparison of DAO and GAD Indicators (Triple Interaction)*/
/*Columns 1-6*/

/*Specialized*/
#delimit;
svy: reg specialized year##workshop##DAO;
outreg2 using "tables\TableF1", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^) replace;
svy: reg specialized year##workshop##DAO i.capital literacy surface_area lag   i.state_region;
outreg2 using "tables\TableF1", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^);
svy: reg favoritism year##workshop##DAO;
outreg2 using "tables\TableF1", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^);
svy: reg favoritism year##workshop##DAO i.capital literacy surface_area lag   i.state_region;
outreg2 using "tables\TableF1", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^);
svy: reg transparency year##workshop##DAO ;
outreg2 using "tables\TableF1", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^) ;
svy: reg transparency year##workshop##DAO  i.capital literacy surface_area lag   i.state_region;
outreg2 using "tables\TableF1", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^);

#delimit;
svy: reg specialized year##workshop##DAO i.capital literacy surface_area lag   i.state_region;
margins , dydx(workshop) by(DAO) at(year=(2018(2)2020));
marginsplot;
graph save "figures\Figure_TripleMFX.gph", replace;
graph export "figures\Figure_TripleMFX.pdf", as(pdf) replace;
/***********************************************************************************************************************************************************/

/***********************************************************************************************************************************************************/
/*Table F3 Direct Comparison of DAO and GAD Index Indicators (Triple Interaction w/ Only Clustered SEs)*/

/*Cluster SE*/
#delimit;
reg specialized year##workshop##DAO, cluster(township);
outreg2 using "tables\TableF3", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^) replace;
areg specialized year##workshop##DAO i.capital literacy surface_area lag , absorb(state_region) cluster(township);
outreg2 using "tables\TableF3", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^);
reg favoritism year##workshop##DAO, cluster(township);
outreg2 using "tables\TableF3", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^);
areg favoritism year##workshop##DAO i.capital literacy surface_area lag,   absorb(state_region) cluster(township);
outreg2 using "tables\TableF3", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^);
reg transparency year##workshop##DAO , cluster(township);
outreg2 using "tables\TableF3", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^) ;
areg transparency year##workshop##DAO  i.capital literacy surface_area lag,   absorb(state_region) cluster(township);
outreg2 using "tables\TableF3", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^) excel;
/***********************************************************************************************************************************************************/

/***********************************************************************************************************************************************************/
/*Township Level*/
#delimit;
collapse helpful info workshop capital literacy surface_area lag GAD_indicators_final specialized, by(year p_code DAO state_region);

/***********************************************************************************************************************************************************/
/*Table F1 Direct Comparison of DAO and GAD Indicators (Triple Interaction)*/
/*Columns 1-6*/
reg helpful year##workshop##DAO , robust;
outreg2 using "tables\TableF1", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^) ;
reg helpful year##workshop##DAO  i.capital literacy surface_area lag   i.state_region, robust;
outreg2 using "tables\TableF1", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^);
reg info year##workshop##DAO , robust;
outreg2 using "tables\TableF1", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^) ;
reg info year##workshop##DAO  i.capital literacy surface_area lag   i.state_region, robust;
outreg2 using "tables\TableF1", tdec(3) bdec(3) e(rmse) alpha(0.001, 0.01, 0.05, 0.1) symbol(***, **, *, ^) excel;
/***********************************************************************************************************************************************************/





















